home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
ezhint.exe
/
READ.ME
< prev
next >
Wrap
Text File
|
1992-12-09
|
3KB
|
75 lines
This file demonstrates a simple method of implementing the 'hint'
functionality of Turbo Vision status lines. Hints are text that appears to
the right on the status line, and is seperated from the status line items
by a vertical line. Hints are somewhat like 'quick and dirty help' messages;
the hint that appears is determined by the focused item's help context.
In general, implementing hints is easy - you just derive a new class
from TStatusLine, and override the hint() method. The new hint() method is
passed a ushort that is a help context; it needs to return a const char * to
an asciiz string that represents the 'hint' for that context.
Since help contexts need to start at 1000 (TV reserves 0..999), and
because of the nature of collections, its difficult to instantiate a string
collection to correspond to these help contexts. To the rescue is my Strings
class uploaded to the BCPPDOS forum (TV section) on CIS. Though the initial
reason I wrote this class was for a completely different reason (easy use
of String Resource files), it works very well as a source of the string
information for status line hints.
The way it ties together is this: First, you need to derive the new
TStatusLine class that overrides the hint() method. In EZHINT.CPP, this new
class is called THintStatusLine. This class has a Strings member, which is
initialized in the THintStatusLine ctor. There are 2 ways to initialize a
Strings object: call load() with char * - this initializes the object from a
String Resource file; alternatively, you can call load() with a statically
allocate an array of StrRef items (see STRINGS.H) - this is the method
demonstrated in EZHINT.CPP.
class THintStatusLine : public TStatusLine
{
public:
THintStatusLine( const TRect& bounds, TStatusDef& aDefs );
virtual const char *hint( ushort aHelpCtx );
protected:
Strings s;
};
StrRef strRef[] = {
{ hcCtx1, "help 1" },
{ hcCtx2, "help 2" },
{ hcCtx3, "help 3" },
{ srNull, 0 }
};
THintStatusLine::THintStatusLine( const TRect& bounds,
TStatusDef& aDefs ) :
TStatusLine(bounds, aDefs)
{
s.load(strRef);
}
Next, you must declare what the new hint() method does: this is very
simple because it either returns s[helpCtx] (s is the Strings member) if this
is a non-null value, or "" (ie helpCtx was not in s). Note that you can't
just return a null pointer - TStatusLine::draw() freaks on this and prints
spurious characters:
const char *THintStatusLine::hint( ushort aHelpCtx )
{
char *p = s[aHelpCtx];
if( p == 0 )
return "";
else
return p;
}
That's really all there is to it!
Pat Reilly (TeamB)
70274,161